/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1160.breakaway.model;

import java.util.Vector;

/**
 *
 * @author FireBird Robotics
 */
public class Robot {
    //Virtual robot to be accessed by classes that need info
    
    //Instance Fields
    ///////////////////////////////////////////////////////////////////////////
    protected static final Robot MODEL = new Robot();//This is the instance that is modified

    //Model Listener Notification
    protected Vector modelListeners = new Vector();

    //State, Teleop/Auto + Init/Periodic/Continous
    protected byte state;

    //Drive Models
    protected double d_speed;
    protected double d_turn;

    //dribbler
    ////////////////////////////////////////////////////////////////////////////
    protected boolean dr_isOn;


    //Constructors
    ////////////////////////////////////////////////////////////////////////////
    private Robot(){
        this.state = 0;
        this.d_speed = 0;
        this.d_turn = 0;
        this.dr_isOn = false;
    }

    //Methods
    ////////////////////////////////////////////////////////////////////////////


    //Accessor Methods
    ////////////////////////////////////////////////////////////////////////////


    /**
     * This method returns the only instance that will exist
     * @return Model Robot Object for other systems
     */
    public static Robot getModel() throws NullPointerException{
        if(MODEL != null)
            return MODEL;
        else
            throw new NullPointerException("Cannotn init Model");
    }

    public byte getState(){
        return state;
    }

    public double getSpeed() {
        return d_speed;
    }
    public double getCurve() {
        return d_turn;
    }

    //Mutator Methods
    ////////////////////////////////////////////////////////////////////////////
    /**
     * This method sets the state following the sum of the two related constants
     * from the below package. This should be called at the beginning each
     * change of state.
     *
     * @param Sum of two related Constants, com.team1160.breakaway.api.Constants
     */
    public void setState(int val){
        state = (byte) val;
    }

    /**
     * This method sets the state following the sum of the two related constants
     * from the below package. This should be called at the beginning each
     * change of state.
     *
     * @param Sum of two related Constants, com.team1160.breakaway.api.Constants
     */
    public void setState(byte val){
        this.state = val;
    }

    public void setSpeed(int speed){
        this.d_speed = speed;
    }

    //Model Listener Notifications
    public void addModelListener(ModelListener m){
        this.modelListeners.addElement(m);
    }

    public Vector getModelListeners(){
        return this.modelListeners;
    }

    protected void processModelChange(RobotEvent e){
        for(int i = 0;i < this.modelListeners.size();++i){
            ((ModelListener)(this.modelListeners.elementAt(i))).stateChange(e);
        }
    }

}
